package xcmg.device.web.basic;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import xcmg.device.infra.AuthCode;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.infra.StringUtil;
import xcmg.device.service.basic.DataDictionaryService;
import xcmg.device.service.basic.MaterialsService;
import xcmg.device.service.company.CompanyInfoService;
import xcmg.device.service.vo.FunctionResult;
import xcmg.device.service.vo.basic.*;
import xcmg.device.service.vo.warehouse.InventoryMaterialsSearchVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * Created by GYJ on 2017-12-22.
 */
@RestController
@RequestMapping("/materials")
public class MaterialsController extends BasicController {
    @Autowired
    private MaterialsService materialsService;
    @Autowired
    private HttpServletRequest httpServletRequest;

    @Autowired
    private CompanyInfoService companyInfoService;

    @Autowired
    private DataDictionaryService dataDictionaryService;

    private static final String WEIGHT_UNIT = "KG";

    private static final String MATERIAL_FILTER = "MATERIAL_FILTER";

    //非直投只查询自己的零件信息的过滤配置
    private static final String SELF_MATERIAL_FILTER = "SELF_MATERIAL_FILTER";

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult list(@RequestBody SearchCommonVO<MaterialsSearchVO> searchVO) throws Exception {
        if (StringUtils.isEmpty(searchVO.getFilters().getOrgId())) {
            searchVO.getFilters().setOrgId(getOrgId());
        }
        searchVO.getFilters().setShowValid(1);
        PageCommonVO<MaterialsVO> result = materialsService.list(searchVO);
        //处理替换零件
//        processReplcaceMateria(result.getPageInfoList());
        return actionValueResult(result.getPageInfo());
    }

    @RequestMapping(value = "/querySupplierMaterials", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult querySupplierMaterials(@RequestBody SearchCommonVO<MaterialsSearchVO> searchVO) throws Exception {
        searchVO.getFilters().setShowValid(1);
        searchVO.getFilters().setDownOrgId(getOrgId());
        PageCommonVO<MaterialsVO> result = materialsService.querySupplierMaterials(searchVO);
        return actionValueResult(result.getPageInfo());
    }

    @RequestMapping(value = "/querySupplierList", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult<PageInfo<MaterialsSupplierVO>> querySupplierList(@RequestBody SearchCommonVO<MaterialsSupplierVO> searchVO) throws Exception {
        PageCommonVO<MaterialsSupplierVO> materialsSuppliers = materialsService.querySupplierList(searchVO, getOrgId());
        return actionValueResult(materialsSuppliers.getPageInfo());
    }

    @RequestMapping(value = "/listForOut", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult listForOut(@RequestBody SearchCommonVO<MaterialsVO> searchVO) throws Exception {
        if (StringUtils.isEmpty(searchVO.getFilters().getOrgId())) {
            searchVO.getFilters().setOrgId(getOrgId());
        }
        PageCommonVO<MaterialsVO> result = materialsService.listForOut(searchVO);
        return actionValueResult(result.getPageInfo());
    }

    @RequestMapping(value = "/listByCode", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult listByCode(@RequestBody SearchCommonVO<InventoryMaterialsSearchVO> searchVO) throws Exception {
        if (StringUtils.isEmpty(searchVO.getFilters().getOrgId())) {
            searchVO.getFilters().setOrgId(getOrgId());
        }
        PageCommonVO<MaterialsVO> result = materialsService.listByCode(searchVO);
        return actionValueResult(result.getPageInfo());
    }

    @RequestMapping(value = "/supplierList", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult supplierList(@RequestBody SearchCommonVO<MaterialsSearchVO> searchVO) throws Exception {
        PageCommonVO<MaterialsVO> result = materialsService.list(searchVO);
        return actionValueResult(result.getPageInfo());
    }

    @RequestMapping(value = "/purchaseMaterialsList", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult purchaseMaterialsList(@RequestBody SearchCommonVO<MaterialsSearchVO> searchVO) throws Exception {
        if (StringUtils.isEmpty(searchVO.getFilters().getOrgId())) {
            searchVO.getFilters().setOrgId(getOrgId());
        }
        if (StringUtils.isEmpty(searchVO.getFilters().getDealerOrgId())) {
            searchVO.getFilters().setDealerOrgId(getOrgId());
        }

        PageCommonVO<MaterialsVO> result = materialsService.purchaseMaterialsList(searchVO, getOrgId(), false);
        return actionValueResult(result.getPageInfo());
    }

    @RequestMapping(value = "/purchaseMaterialsListByFilter", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult purchaseMaterialsListByFilter(@RequestBody SearchCommonVO<MaterialsSearchVO> searchVO) throws Exception {
        if (StringUtils.isEmpty(searchVO.getFilters().getOrgId())) {
            searchVO.getFilters().setOrgId(getOrgId());
        }
        if (StringUtils.isEmpty(searchVO.getFilters().getDealerOrgId())) {
            searchVO.getFilters().setDealerOrgId(getOrgId());
        }
        String orgId = getOrgId();
        //检查是否配置了选择零件时需要过滤
        DictionaryRelationVO dictionaryRelationVO = new DictionaryRelationVO();
        dictionaryRelationVO.setParentCode(MATERIAL_FILTER);
        List<DictionaryRelationVO> dictionaryRelationVOS = dataDictionaryService.searchList(dictionaryRelationVO);

        boolean filter = false;
        if (dictionaryRelationVOS != null) {
            Optional<DictionaryRelationVO> dictionaryRelationVOOptional = dictionaryRelationVOS.stream().filter(item -> StringUtils.equals(item.getCode(), orgId)).findAny();
            //如果存在，则说明配置了过滤
            if (dictionaryRelationVOOptional.isPresent()) {
                filter = true;
            }
        }

        DataDictionaryVO dictVO = dataDictionaryService.itemByCode(SELF_MATERIAL_FILTER, orgId);
        Boolean selfMaterialFlag = false;
        if (dictVO != null) {
            selfMaterialFlag = true;
        }

        PageCommonVO<MaterialsVO> result = null;
        if (filter) {
            if (!StringUtils.equals(searchVO.getFilters().getOrgId(), orgId)) {
                searchVO.getFilters().setSupplierOrgId(searchVO.getFilters().getOrgId());
                searchVO.getFilters().setOrgId(orgId);
            }
            result = materialsService.purchaseMaterialsListByFilter(searchVO, getOrgId(), selfMaterialFlag);
        } else {

            result = materialsService.purchaseMaterialsList(searchVO, getOrgId(), selfMaterialFlag);
        }
        //处理替换零件
//        processReplcaceMateria(result.getPageInfoList());
        return actionValueResult(result.getPageInfo());
    }


    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true, code = AuthCode.Materiel.ADD)
    public ActionResult add(@RequestBody MaterialsVO model) throws Exception {
        model.setOrgId(getOrgId());
        if (model.getMaterialsNo() == null) {
            return actionResult(ErrorCode.MaterialsNoIsNull);
        }
        if (getWordCount(model.getMaterialsNo()) > 20) {
            return actionResult(ErrorCode.MaterialsNoTooLong);
        }
        BigDecimal weight = model.getWeight();
        if (weight != null && StringUtils.isEmpty(model.getWeightUnit())) {
            model.setWeightUnit(WEIGHT_UNIT);
        }
        String userId = getUserId(httpServletRequest);
        model.setCreateId(userId);
        ErrorCode ret = materialsService.add(model);
        return actionResult(ret);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true, code = AuthCode.Materiel.EDIT)
    public ActionResult update(@RequestBody MaterialsVO model) throws Exception {
        if (model.getMaterialsNo() == null) {
            return actionResult(ErrorCode.MaterialsNoIsNull);
        }
        model.setOrgId(getOrgId());
        String userId = getUserId(httpServletRequest);
        model.setUpdateId(userId);
        BigDecimal weight = model.getWeight();//默认设置未KG
        if (weight != null && StringUtil.isEmpty(model.getWeightUnit())) {
            model.setWeightUnit(WEIGHT_UNIT);
        }
        ErrorCode ret = materialsService.update(model);
        return actionResult(ret);
    }

    @RequestMapping(value = "/item", method = RequestMethod.GET)
    @FastMappingInfo(needLogin = true)
    public ActionResult item(String materialsId) {
        if (materialsId == null) {
            return actionResult(ErrorCode.MaterialsNoIsNull);
        }
        MaterialsVO materialsVO = materialsService.item(materialsId);
        if (materialsVO == null) {
            return actionResult(ErrorCode.MaterialsNotExists);
        }
        //处理替换零件
//        processReplcaceMateria(Arrays.asList(materialsVO));
        return actionValueResult(materialsVO);
    }

    @RequestMapping(value = "/export", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true, code = AuthCode.Materiel.EXPORT)
    public void export(String[] materialsIds) throws Exception {
        materialsService.export(Arrays.asList(materialsIds));
    }

    @RequestMapping(value = "/exportAll", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true, code = AuthCode.Materiel.EXPORT)
    public void exportAll(MaterialsSearchVO condition) throws Exception {
        condition.setOrgId(getOrgId());
        materialsService.exportAll(condition);
    }

    @RequestMapping(value = "/download", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public void download() throws Exception {
        materialsService.download();
    }


    @ResponseBody
    @RequestMapping(value = "/import", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true, code = AuthCode.Materiel.IMPORT)
    public ActionResult importExcel(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
        String fileName = file.getOriginalFilename();
        FunctionResult<String> result = new FunctionResult<>();
        if (!fileName.trim().endsWith(".xls")) {
            result.setCode(ErrorCode.ImportExcelEndWithXLS);
        } else {
            InputStream in = file.getInputStream();
            String orgId = getOrgId();
            String sapCode = companyInfoService.getSapCodeByOrgId(orgId);
            result = materialsService.importExcel(in, fileName, orgId, getUserId());
        }
        return actionResult(result.getCode(), result.getValue());
    }

    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true, code = AuthCode.Materiel.DEL)
    public ActionResult remove(@RequestBody String[] ids) {
        if (ids == null) {
            return actionResult(ErrorCode.MaterialsNoIsNull);
        }
        String userId = getUserId(httpServletRequest);
        ErrorCode ret = materialsService.remove(Arrays.asList(ids), userId);
        return actionResult(ret);
    }

    @ResponseBody
    @RequestMapping(value = "/importLocationExcel", method = RequestMethod.POST)
    @ApiOperation("零件批量导入库存仓库")
    @FastMappingInfo(needLogin = true)
    public ActionResult importLocationExcel(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
        String fileName = file.getOriginalFilename();
        FunctionResult<String> result = new FunctionResult<>();
        if (!fileName.trim().endsWith(".xls")) {
            result.setCode(ErrorCode.ImportExcelEndWithXLS);
        } else {
            result = materialsService.importLocationExcel(file, getOrgId(), getUserId());
        }
        return actionResult(result.getCode(), result.getValue());
    }

    @RequestMapping(value = "/downloadLocationExcel", method = RequestMethod.POST)
    @ApiOperation("下载零件储位导入模板")
    @FastMappingInfo(needLogin = true)
    public void downloadLocationExcel() throws Exception {
        materialsService.downloadLocationExcel();
    }

    @RequestMapping(value = "/locationRelationList", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    @ApiOperation("查询零件编码关系列表")
    public ActionResult locationRelationList(@RequestBody SearchCommonVO<MaterialLocationRelationVO> searchVO) throws Exception {
        searchVO.getFilters().setOrgId(getOrgId());
        return actionValueResult(materialsService.locationRelationList(searchVO).getPageInfo());
    }

    @RequestMapping(value = "/findDefaultLocation", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    @ApiOperation("根据零件和仓库库区查询默认储位")
    public ActionResult findDefaultLocation(@RequestBody DefaultLocationSearchVO searchVO) throws Exception {
        searchVO.setOrgId(getOrgId());
        return actionValueResult(materialsService.findDefaultLocation(searchVO));
    }

    @ResponseBody
    @RequestMapping(value = "/importTyprEntranceCruciaLExcel", method = RequestMethod.POST)
    @ApiOperation("零件批量导入导入零件分类和是否进口件和关键件")
    @FastMappingInfo(needLogin = true)
    public ActionResult importTyprEntranceCruciaLExcel(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
        String fileName = file.getOriginalFilename();
        FunctionResult<String> result = new FunctionResult<>();
        if (!fileName.trim().endsWith(".xls")) {
            result.setCode(ErrorCode.ImportExcelEndWithXLS);
        } else {
            result = materialsService.importTyprEntranceCruciaLExcel(file, getOrgId());
        }
        return actionResult(result.getCode(), result.getValue());
    }

    @RequestMapping(value = "/downloadTyprEntranceCrucialExcel", method = RequestMethod.POST)
    @ApiOperation("下载零件分类及是否进口件和关键件导入模板")
    @FastMappingInfo(needLogin = true)
    public void downloadTyprEntranceCrucialExcel() throws Exception {
        materialsService.downloadTyprEntranceCrucialExcel();
    }

    @RequestMapping(value = "/importReplace", method = RequestMethod.POST)
    @ApiOperation("批量导入替换零件和改型零件")
    @FastMappingInfo(needLogin = true)
    public ActionResult importReplace(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
        String fileName = file.getOriginalFilename();
        FunctionResult<String> result = new FunctionResult<>();
        if (!fileName.trim().endsWith(".xls")) {
            result.setCode(ErrorCode.ImportExcelEndWithXLS);
        } else {
            result = materialsService.importReplace(file, getOrgId());
        }
        return actionResult(result.getCode(), result.getValue());
    }

    @RequestMapping(value = "/downloadReplace", method = RequestMethod.POST)
    @ApiOperation("下载批量导入替换零件和改型零件模板")
    @FastMappingInfo(needLogin = true)
    public void downloadReplace() throws Exception {
        materialsService.downloadReplace();
    }

    @ResponseBody
    @RequestMapping(value = "/importKeeperExcel", method = RequestMethod.POST)
    @ApiOperation("保管员批量导入库存仓库")
    @FastMappingInfo(needLogin = true)
    public ActionResult importKeeperExcel(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
        String fileName = file.getOriginalFilename();
        FunctionResult<String> result = new FunctionResult<>();
        if (!fileName.trim().endsWith(".xls")) {
            result.setCode(ErrorCode.ImportExcelEndWithXLS);
        } else {
            result = materialsService.importKeeper(file, getOrgId());
        }
        return actionResult(result.getCode(), result.getValue());
    }

    @RequestMapping(value = "/downloadKeeperExcel", method = RequestMethod.POST)
    @ApiOperation("下载保管员批量导入模板")
    @FastMappingInfo(needLogin = true)
    public void downloadKeeperExcel() throws Exception {
        materialsService.downloadKeeper();
    }

    @ResponseBody
    @RequestMapping(value = "/importGroupPurExcel", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult importGroupPurExcel(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
        String fileName = file.getOriginalFilename();
        FunctionResult<String> result = new FunctionResult<>();
        if (!fileName.trim().endsWith(".xls")) {
            result.setCode(ErrorCode.ImportExcelEndWithXLS);
        } else {
            result = materialsService.importGroupPurExcel(file, getOrgId());
        }
        return actionResult(result.getCode(), result.getValue());
    }

    @RequestMapping(value = "/downloadMaterialsPriceExcel", method = RequestMethod.POST)
    @ApiOperation("下载价格导入批量导入模板")
    @FastMappingInfo(needLogin = true)
    public void downloadMaterialsPriceExcel() throws Exception {
        materialsService.downloadMaterialsPrice(getOrgId());
    }

    @ResponseBody
    @RequestMapping(value = "/importMaterialsPrice", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult importMaterialsPrice(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
        String fileName = file.getOriginalFilename();
        FunctionResult<String> result = new FunctionResult<>();
        if (!fileName.trim().endsWith(".xls")) {
            result.setCode(ErrorCode.ImportExcelEndWithXLS);
        } else {
            result = materialsService.importMaterialsPrice(file, getOrgId());
        }
        return actionResult(result.getCode(), result.getValue());
    }

    @RequestMapping(value = "/downloadGroupPurExcel", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public void downloadGroupPurExcel() throws Exception {
        materialsService.downloadGroupPurExcel();
    }

    /**
     * 以字节为单位的字符串长度
     *
     * @param s
     * @return
     */
    public static int getWordCount(String s) {
        int length = 0;
        for (int i = 0; i < s.length(); i++) {
            int ascii = Character.codePointAt(s, i);
            if (ascii >= 0 && ascii <= 255) {
                length++;
            } else {
                length += 3;
            }
        }
        return length;
    }


//    @RequestMapping(value = "weightTemplete/download", method = RequestMethod.POST)
//    public void downloadMaterialWeightTemplete(HttpServletResponse response) throws Exception {
//        materialsService.downloadMaterialWeightExcel();
//    }
//    @RequestMapping(value = "weight/import", method = RequestMethod.POST)
//    public ActionResult materialWeightImport(HttpServletRequest request) throws Exception {
//        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
//        String fileName = file.getOriginalFilename();
//        FunctionResult<String> result = new FunctionResult<>();
//        if (!fileName.trim().endsWith(".xls")) {
//            result.setCode(ErrorCode.ImportExcelEndWithXLS);
//        } else {
//            result = materialsService.importMaterialWeight(file, getOrgId());
//        }
//        return actionResult(result.getCode(), result.getValue());
//    }
//    @RequestMapping(value = "/getAuthDeviceTemplate", method = RequestMethod.POST)
//    @ApiOperation("下载认证件导入模板")
//    @FastMappingInfo(needLogin = true)
//    public void getAuthDeviceTemplate() throws Exception {
//        materialsService.getAuthDeviceTemplate();
//    }
//    @ResponseBody
//    @RequestMapping(value = "/importAuthDevice", method = RequestMethod.POST)
//    @ApiOperation("导入认证件")
//    @FastMappingInfo(needLogin = true)
//    public ActionResult importAuthDevice(HttpServletRequest request) throws Exception {
//        // public ActionResult importAuthDevice(MultipartFile file) throws Exception{
//        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//        MultipartFile file = multipartRequest.getFile(multipartRequest.getFileNames().next());
//        String fileName = file.getOriginalFilename();
//        FunctionResult<String> result = new FunctionResult<>();
//        if (!fileName.trim().endsWith(".xls")) {
//            result.setCode(ErrorCode.ImportExcelEndWithXLS);
//        } else {
//            InputStream in = file.getInputStream();
//            result = materialsService.importAuthDevice(in, getOrgId());
//        }
//        return actionResult(result.getCode(), result.getValue());
//    }

//    @ResponseBody
//    @RequestMapping(value = "/setAuthDeviceLimit", method = RequestMethod.POST)
//    @ApiOperation("设置只看认证件代理商客户")
//    @FastMappingInfo(needLogin = true)
//    //orgId:platOrgId
//    public ActionResult setAuthDeviceLimit(@RequestBody AuthDeviceLimitVO authDeviceLimitVO) throws Exception {
//        return actionResult(materialsService.setAuthDeviceLimit(authDeviceLimitVO, getOrgId()));
//    }
//    @ResponseBody
//    @RequestMapping(value = "/unSetAuthDeviceLimit", method = RequestMethod.POST)
//    @ApiOperation("设置只看认证件代理商客户")
//    @FastMappingInfo(needLogin = true)
//    //orgId:platOrgId
//    public ActionResult unSetAuthDeviceLimit(@RequestBody AuthDeviceLimitVO authDeviceLimitVO) throws Exception {
//        return actionResult(materialsService.unSetAuthDeviceLimit(authDeviceLimitVO, getOrgId()));
//    }
//    @ResponseBody
//    @RequestMapping(value = "/getAuthDeviceLimitList", method = RequestMethod.POST)
//    @ApiOperation("查看客户信息")
//    @FastMappingInfo(needLogin = true)
//    public ActionResult getAuthDeviceLimitList(@RequestBody SearchCommonVO<AuthConditionVO> condition) throws Exception {
//        return actionResult(materialsService.getAuthDeviceLimitList(condition, getOrgId()).getPageInfo());
//    }
//    @RequestMapping(value = "/getOemInfos", method = RequestMethod.GET)
//    @ApiOperation(value = "查询一级代理商对应的主机厂信息")
//    @FastMappingInfo(needLogin = true)
//    public ActionResult getOemInfos() throws Exception {
//        return actionResult(materialsService.getOemInfos(getOrgId()));
//    }
//
//    @RequestMapping(value = "/getPricePlan", method = RequestMethod.GET)
//    @ApiOperation(value = "查询一级级代理商对应主机厂价格方案")
//    @FastMappingInfo(needLogin = true)
//    public ActionResult getPricePlan(String oemOrgId) throws Exception {
//        return actionResult(materialsService.getPricePlan(oemOrgId, getOrgId()));
//    }

//    @RequestMapping(value = "/pullInfos", method = RequestMethod.POST)
//    @ApiOperation(value = "拉取未拉取的零件和价格方案")
//    @FastMappingInfo(needLogin = true)
//    public ActionResult pullInfos() throws Exception {
//        materialsService.setPullMaterialRecord();
//        materialsService.setPullMarketRecord();
//        materialsService.pullInfos();
//        return actionResult(ErrorCode.Success);
//    }
//
//    @RequestMapping(value = "/pullMaterialInfos", method = RequestMethod.POST)
//    @ApiOperation(value = "从ERP拉取零件信息")
//    @FastMappingInfo(needLogin = true)
//    public ActionResult pullMaterialInfos(@RequestBody MaterialPullCondition materialPullCondition) throws Exception {
//        materialsService.setPullMaterialRecord();
////    	materialsService.manualPullMaterialInfos(materialPullCondition);
//        return actionResult(ErrorCode.Success);
//    }
//
//    @RequestMapping(value = "/pullPriceMarket", method = RequestMethod.POST)
//    @ApiOperation(value = "从ERP拉取价格方案")
//    @FastMappingInfo(needLogin = true)
//    public ActionResult pullPriceMarket(@RequestBody PriceMarketPullCondition priceMarketPullCondition) throws Exception {
//        materialsService.setPullMarketRecord();
////    	materialsService.manualPullPriceMarket(priceMarketPullCondition);
//        return actionResult(ErrorCode.Success);
//    }
//
//    @RequestMapping(value = "/pushMarketRecord", method = RequestMethod.GET)
//    @ApiOperation(value = "同步价格方案")
//    public ActionResult pushMarketRecord() throws Exception {
//        materialsService.setPushMarketRecord();
//        materialsService.pushConRecords();
//        return actionResult(ErrorCode.Success);
//    }

    @RequestMapping(value = "/suplierFactoryIds", method = RequestMethod.GET)
    @FastMappingInfo(needLogin = true)
    public ActionResult<List<String>> suplierFactoryIds(@RequestParam(name = "factoryIdLike",required = false) String factoryIdLike) throws Exception {
        return actionValueResult(materialsService.suplierFactoryIds(factoryIdLike,getOrgId()));
    }
}
